/*
 *此javaCode由YMS-JDBC替换工具生成，原mapper位置com.yonyou.ucf.mdf.app.isvdxq.other.mapper.WarehouseMapper
 */
package com.yonyou.ucf.mdf.app.isvdxq.other.mapper.impl;

import com.yonyou.iuap.yms.api.IYmsJdbcApi;
import com.yonyou.iuap.yms.param.*;
import com.yonyou.iuap.yms.param.ResultSetProcessor;
import com.yonyou.iuap.yms.processor.*;
import com.yonyou.iuap.yms.replace.CollectionUtil;
import com.yonyou.ucf.mdf.app.isvdxq.firstpart.RFIDCodeDetail.model.Warehouse;
import com.yonyou.ucf.mdf.app.isvdxq.other.entity.WarehouseEntity;
import java.sql.Types;
import java.util.*;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

@Repository
public class WarehouseMapperImpl  {
    
    @Autowired
    private IYmsJdbcApi ymsJdbcApi;
    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.WarehouseMapper.selectAll
    
    public List<WarehouseEntity> selectAll(String tenantId) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "select * from dxqyy_warehouse where `isEnabled`='true' and `ytenant_id` = ?;\n";
        parameter.addParamWithType(tenantId, Types.VARCHAR);

        ResultSetProcessor processor = new AutoBeanListProcessor(new WarehouseEntity());
        return (List<WarehouseEntity>) ymsJdbcApi.queryForList(sql, parameter, processor);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.WarehouseMapper.GetwarehouseByorgIds
    
    public List<WarehouseEntity> GetwarehouseByorgIds(List<String> orgids, String tenantId) {
        SQLParameter parameter = new SQLParameter(true);
        StringBuilder sqlBuilder = new StringBuilder();
		sqlBuilder.append(" select id from `dxqyy_warehouse` where ytenant_id=? ");
		parameter.addParam(tenantId);
		if (CollectionUtil.isNotEmpty(orgids)) {
			sqlBuilder.append(" and org in ");
			sqlBuilder.append(" ( ");
			String separator0 = " , ";
			for (int index = 0; index < orgids.size(); index++) {
				String item = orgids.get(index);
				sqlBuilder.append(" ? ");
				parameter.addParam(item);
				if (index < orgids.size() - 1) {
					sqlBuilder.append(separator0);
				}
			}
			sqlBuilder.append(" ) ");
		}else{
			sqlBuilder.append(" and org in ('')");
		}
        
        String sql = sqlBuilder.toString();
        ResultSetProcessor processor = new AutoBeanListProcessor(new WarehouseEntity());
        return (List<WarehouseEntity>) ymsJdbcApi.queryForList(sql, parameter, processor);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.WarehouseMapper.updateByPrimaryKey
    
    public int updateByPrimaryKey(WarehouseEntity record) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "update dxqyy_warehouse set `code` = ?, `warehouseName` = ?, `org` = ?, `org_name` = ?, `ownerorg` = ?, `ownerorg_name` = ?, `shopDefault` = ?, `iUsed` = ?, `bMRP` = ?, `joinStockQuery` = ?, `stockCheckType` = ?, `iSerialManage` = ?, `isGoodsPosition` = ?, `isGoodsPositionStock` = ?, `eStore` = ?, `wStore` = ?, `bWMS` = ?, `isSubcontractW` = ?, `isInvertedScour` = ?, `countCost` = ?, `isWasteWarehouse` = ?, `isEnabled` = ?, `modifier` = ?, `modifierId` = ?, `modifyTime` = ?, `creator` = ?, `creatorId` = ?, `createTime` = ?  where `id` = ? and `ytenant_id` = ?; ";
        parameter.addParamWithType(record.getCode(), Types.VARCHAR);
		parameter.addParamWithType(record.getWarehouseName(), Types.VARCHAR);
		parameter.addParamWithType(record.getOrg(), Types.VARCHAR);
		parameter.addParamWithType(record.getOrg_name(), Types.VARCHAR);
		parameter.addParamWithType(record.getOwnerorg(), Types.VARCHAR);
		parameter.addParamWithType(record.getOwnerorg_name(), Types.VARCHAR);
		parameter.addParamWithType(record.getShopDefault(), Types.VARCHAR);
		parameter.addParamWithType(record.getiUsed(), Types.VARCHAR);
		parameter.addParamWithType(record.getbMRP(), Types.VARCHAR);
		parameter.addParamWithType(record.getJoinStockQuery(), Types.VARCHAR);
		parameter.addParamWithType(record.getStockCheckType(), Types.VARCHAR);
		parameter.addParamWithType(record.getiSerialManage(), Types.VARCHAR);
		parameter.addParamWithType(record.getIsGoodsPosition(), Types.VARCHAR);
		parameter.addParamWithType(record.getIsGoodsPositionStock(), Types.VARCHAR);
		parameter.addParamWithType(record.geteStore(), Types.VARCHAR);
		parameter.addParamWithType(record.getwStore(), Types.VARCHAR);
		parameter.addParamWithType(record.getbWMS(), Types.VARCHAR);
		parameter.addParamWithType(record.getIsSubcontractW(), Types.VARCHAR);
		parameter.addParamWithType(record.getIsInvertedScour(), Types.VARCHAR);
		parameter.addParamWithType(record.getCountCost(), Types.DECIMAL);
		parameter.addParamWithType(record.getIsWasteWarehouse(), Types.VARCHAR);
		parameter.addParamWithType(record.getIsEnabled(), Types.VARCHAR);
		parameter.addParamWithType(record.getModifier(), Types.VARCHAR);
		parameter.addParamWithType(record.getModifierId(), Types.VARCHAR);
		parameter.addParamWithType(record.getModifyTime(), Types.VARCHAR);
		parameter.addParamWithType(record.getCreator(), Types.VARCHAR);
		parameter.addParamWithType(record.getCreatorId(), Types.VARCHAR);
		parameter.addParamWithType(record.getCreateTime(), Types.VARCHAR);
		parameter.addParamWithType(record.getId(), Types.BIGINT);
		parameter.addParamWithType(record.getTenantId(), Types.VARCHAR);

        
        return ymsJdbcApi.update(sql, parameter);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.WarehouseMapper.selectCount
    
    public int selectCount(long id, String tenantId) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "select count(1) from dxqyy_warehouse where `id`=? and `ytenant_id`=?;\n";
        parameter.addParamWithType(id, Types.BIGINT);
		parameter.addParam(tenantId);

        ResultSetProcessor processor = new ColumnProcessor(int.class);
        return (int) ymsJdbcApi.queryForObject(sql, parameter, processor);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.WarehouseMapper.insertBatch
    
    public int insertBatch(List<WarehouseEntity> insertBatch) {
        SQLParameter parameter = new SQLParameter(true);
        StringBuilder sqlBuilder = new StringBuilder();
		sqlBuilder.append(" insert into dxqyy_warehouse (`id`, `code`, `warehouseName`, `org`, `org_name`, `ownerorg`, `ownerorg_name`, `shopDefault`, `iUsed`, `bMRP`, `joinStockQuery`, `stockCheckType`, `iSerialManage`, `isGoodsPosition`, `isGoodsPositionStock`, `eStore`, `wStore`, `bWMS`, `isSubcontractW`, `isInvertedScour`, `countCost`, `isWasteWarehouse`, `isEnabled`, `modifier`, `modifierId`, `modifyTime`, `creator`, `creatorId`, `createTime`, `ytenant_id`) values ");
		if (CollectionUtil.isNotEmpty(insertBatch)) {
			String separator0 = " , ";
			for (int i = 0; i < insertBatch.size(); i++) {
				WarehouseEntity item = insertBatch.get(i);
				sqlBuilder.append(" (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ");
				parameter.addParamWithType(item.getId(), Types.BIGINT);
				parameter.addParamWithType(item.getCode(), Types.VARCHAR);
				parameter.addParamWithType(item.getWarehouseName(), Types.VARCHAR);
				parameter.addParamWithType(item.getOrg(), Types.VARCHAR);
				parameter.addParamWithType(item.getOrg_name(), Types.VARCHAR);
				parameter.addParamWithType(item.getOwnerorg(), Types.VARCHAR);
				parameter.addParamWithType(item.getOwnerorg_name(), Types.VARCHAR);
				parameter.addParamWithType(item.getShopDefault(), Types.VARCHAR);
				parameter.addParamWithType(item.getiUsed(), Types.VARCHAR);
				parameter.addParamWithType(item.getbMRP(), Types.VARCHAR);
				parameter.addParamWithType(item.getJoinStockQuery(), Types.VARCHAR);
				parameter.addParamWithType(item.getStockCheckType(), Types.VARCHAR);
				parameter.addParamWithType(item.getiSerialManage(), Types.VARCHAR);
				parameter.addParamWithType(item.getIsGoodsPosition(), Types.VARCHAR);
				parameter.addParamWithType(item.getIsGoodsPositionStock(), Types.VARCHAR);
				parameter.addParamWithType(item.geteStore(), Types.VARCHAR);
				parameter.addParamWithType(item.getwStore(), Types.VARCHAR);
				parameter.addParamWithType(item.getbWMS(), Types.VARCHAR);
				parameter.addParamWithType(item.getIsSubcontractW(), Types.VARCHAR);
				parameter.addParamWithType(item.getIsInvertedScour(), Types.VARCHAR);
				parameter.addParamWithType(item.getCountCost(), Types.DECIMAL);
				parameter.addParamWithType(item.getIsWasteWarehouse(), Types.VARCHAR);
				parameter.addParamWithType(item.getIsEnabled(), Types.VARCHAR);
				parameter.addParamWithType(item.getModifier(), Types.VARCHAR);
				parameter.addParamWithType(item.getModifierId(), Types.VARCHAR);
				parameter.addParamWithType(item.getModifyTime(), Types.VARCHAR);
				parameter.addParamWithType(item.getCreator(), Types.VARCHAR);
				parameter.addParamWithType(item.getCreatorId(), Types.VARCHAR);
				parameter.addParamWithType(item.getCreateTime(), Types.VARCHAR);
				parameter.addParamWithType(item.getTenantId(), Types.VARCHAR);
				if (i < insertBatch.size() - 1) {
					sqlBuilder.append(separator0);
				}
			}
		}
		sqlBuilder.append(" ON DUPLICATE KEY UPDATE code=VALUES(code), warehouseName=VALUES(warehouseName), org=VALUES(org),org_name=VALUES(org_name), ownerorg=VALUES(ownerorg),ownerorg_name=VALUES(ownerorg_name), shopDefault=VALUES(shopDefault), iUsed=VALUES(iUsed), bMRP=VALUES(bMRP), joinStockQuery=VALUES(joinStockQuery), stockCheckType=VALUES(stockCheckType), iSerialManage=VALUES(iSerialManage), isGoodsPosition=VALUES(isGoodsPosition), isGoodsPositionStock=VALUES(isGoodsPositionStock), eStore=VALUES(eStore), wStore=VALUES(wStore), bWMS=VALUES(bWMS), isSubcontractW=VALUES(isSubcontractW), isInvertedScour=VALUES(isInvertedScour), countCost=VALUES(countCost), isWasteWarehouse=VALUES(isWasteWarehouse), isEnabled=VALUES(isEnabled), modifier=VALUES(modifier), modifierId=VALUES(modifierId), modifyTime=VALUES(modifyTime), creator=VALUES(creator), creatorId=VALUES(creatorId), createTime=VALUES(createTime), tenantId=VALUES(tenantId) ");

        
        String sql = sqlBuilder.toString();
        
        return ymsJdbcApi.update(sql, parameter);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.WarehouseMapper.insert
    
    public int insert(WarehouseEntity record) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "insert into dxqyy_warehouse (`id`, `code`,  `warehouseName`, `org`,  `org_name`, `ownerorg`,  `ownerorg_name`, `shopDefault`,  `iUsed`, `bMRP`, `joinStockQuery`,  `stockCheckType`, `iSerialManage`,  `isGoodsPosition`, `isGoodsPositionStock`,  `eStore`, `wStore`,  `bWMS`, `isSubcontractW`,  `isInvertedScour`, `countCost`,  `isWasteWarehouse`, `isEnabled`,  `modifier`, `modifierId`, `modifyTime`,  `creator`, `creatorId`, `createTime`,  `ytenant_id`) values (?, ?,  ?, ?,  ?, ?,  ?, ?,  ?, ?, ?,  ?, ?,  ?, ?,  ?, ?,  ?, ?,  ?, ?,  ?, ?,  ?, ?, ?,  ?, ?, ?,  ?) ";
        parameter.addParamWithType(record.getId(), Types.BIGINT);
		parameter.addParamWithType(record.getCode(), Types.VARCHAR);
		parameter.addParamWithType(record.getWarehouseName(), Types.VARCHAR);
		parameter.addParamWithType(record.getOrg(), Types.VARCHAR);
		parameter.addParamWithType(record.getOrg_name(), Types.VARCHAR);
		parameter.addParamWithType(record.getOwnerorg(), Types.VARCHAR);
		parameter.addParamWithType(record.getOwnerorg_name(), Types.VARCHAR);
		parameter.addParamWithType(record.getShopDefault(), Types.VARCHAR);
		parameter.addParamWithType(record.getiUsed(), Types.VARCHAR);
		parameter.addParamWithType(record.getbMRP(), Types.VARCHAR);
		parameter.addParamWithType(record.getJoinStockQuery(), Types.VARCHAR);
		parameter.addParamWithType(record.getStockCheckType(), Types.VARCHAR);
		parameter.addParamWithType(record.getiSerialManage(), Types.VARCHAR);
		parameter.addParamWithType(record.getIsGoodsPosition(), Types.VARCHAR);
		parameter.addParamWithType(record.getIsGoodsPositionStock(), Types.VARCHAR);
		parameter.addParamWithType(record.geteStore(), Types.VARCHAR);
		parameter.addParamWithType(record.getwStore(), Types.VARCHAR);
		parameter.addParamWithType(record.getbWMS(), Types.VARCHAR);
		parameter.addParamWithType(record.getIsSubcontractW(), Types.VARCHAR);
		parameter.addParamWithType(record.getIsInvertedScour(), Types.VARCHAR);
		parameter.addParamWithType(record.getCountCost(), Types.DECIMAL);
		parameter.addParamWithType(record.getIsWasteWarehouse(), Types.VARCHAR);
		parameter.addParamWithType(record.getIsEnabled(), Types.VARCHAR);
		parameter.addParamWithType(record.getModifier(), Types.VARCHAR);
		parameter.addParamWithType(record.getModifierId(), Types.VARCHAR);
		parameter.addParamWithType(record.getModifyTime(), Types.VARCHAR);
		parameter.addParamWithType(record.getCreator(), Types.VARCHAR);
		parameter.addParamWithType(record.getCreatorId(), Types.VARCHAR);
		parameter.addParamWithType(record.getCreateTime(), Types.VARCHAR);
		parameter.addParamWithType(record.getTenantId(), Types.VARCHAR);

        
        return ymsJdbcApi.update(sql, parameter);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.WarehouseMapper.deleteByPrimaryKey
    
    public int deleteByPrimaryKey(Long id, String tenantId) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "delete from dxqyy_warehouse where `id` = ? and `ytenant_id` = ?\n";
        parameter.addParamWithType(id, Types.BIGINT);
		parameter.addParamWithType(tenantId, Types.VARCHAR);

        
        return ymsJdbcApi.update(sql, parameter);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.WarehouseMapper.selectById
    
    public WarehouseEntity selectById(long id, String tenantId) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "select * from dxqyy_warehouse where `id`=? and `ytenant_id`=?;\n";
        parameter.addParamWithType(id, Types.BIGINT);
		parameter.addParam(tenantId);

        ResultSetProcessor processor = new AutoBeanProcessor(new WarehouseEntity());
        return (WarehouseEntity) ymsJdbcApi.queryForObject(sql, parameter, processor);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.WarehouseMapper.GetwarehouseById
    
    public List<Warehouse> GetwarehouseById(List<String> ids, String tenantId) throws Exception {
        SQLParameter parameter = new SQLParameter(true);
        StringBuilder sqlBuilder = new StringBuilder();
		sqlBuilder.append(" select id,code,warehouseName from `dxqyy_warehouse` where ytenant_id=? ");
		parameter.addParam(tenantId);
		if (CollectionUtil.isNotEmpty(ids)) {
			sqlBuilder.append(" and id in ( ");
			String separator0 = " , ";
			for (int index = 0; index < ids.size(); index++) {
				String item = ids.get(index);
				sqlBuilder.append(" ? ");
				parameter.addParam(item);
				if (index < ids.size() - 1) {
					sqlBuilder.append(separator0);
				}
			}
			sqlBuilder.append(" ) ");
		}

        
        String sql = sqlBuilder.toString();
        ResultSetProcessor processor = new AutoBeanListProcessor(new Warehouse());
        return (List<Warehouse>) ymsJdbcApi.queryForList(sql, parameter, processor);
    }

	public Integer ExeSQL(String sql, SQLParameter parameter){
		return ymsJdbcApi.update(sql, parameter);
	}
}
